package com.chima.service.impl;
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;
import com.chima.dao.AddWorkDao;
import com.chima.domain.AddWork;
import com.chima.domain.PageRequestBean;
import com.chima.domain.PageResponseBean;
import com.chima.service.AddWorkService;
public class AddWorkServiceImp implements AddWorkService {
	private AddWorkDao addWorkDao;
	
   
	public AddWorkDao getAddWorkDao() {
		return addWorkDao;
	}

	public void setAddWorkDao(AddWorkDao addWorkDao) {
		this.addWorkDao = addWorkDao;
	}

	public PageResponseBean findAddWork(PageRequestBean pageRequestBean) {
		int firstResult =(pageRequestBean.getPage()-1)*pageRequestBean.getLimit();
		int maxResults =pageRequestBean.getLimit();
		int total = addWorkDao.findByTotalCount();
		// 获取分页查询条件
//		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(AddWork.class);
		DetachedCriteria detachedCriteria = pageRequestBean.getCriteria();// 不一定存在
		List<AddWork> addWorks= addWorkDao.findByCriteria(detachedCriteria, firstResult, maxResults);
		PageResponseBean pageResponseBean = new PageResponseBean();
		pageResponseBean.setRows(addWorks);
		pageResponseBean.setTotal(total);
		return pageResponseBean;
	}

	public void saveAddWork(AddWork addWork) {
		addWorkDao.save(addWork);
	}

	public void updateAddWork(AddWork addWork) {
		addWorkDao.update(addWork);
		
	}

	public void deleteAddWork(int id) {
		addWorkDao.delete(id);
		
	}

	public AddWork findById(int id) {
		return addWorkDao.findById(id);
	}

	

}
